﻿using Bootstrap.Helper;
using Bootstrap.Template.InnerItems;
using Bootstrap.Template.TemplateInnerItem;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;

namespace Bootstrap.Control
{
    public class BootstrapDropDownItem : AbstractBootstrapItem, IInnerItem
    {
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public List<AbstractBootstrapItem> InnerList { get; set; }
        public string BadgedValue { get; set; }
        public string Text { get; set; }

        public string GetTemplate()
        {


            StringBuilder result = new StringBuilder();

            BootstrapDropDownItemBeginTemplate beginTemplate = new BootstrapDropDownItemBeginTemplate(
                                                               new BootstrapDropDownTemplateItem()
                                                               {
                                                                   DefaultText = ValueHelper.GetDefaultValue<string>(this.Text, string.Empty)
                                                               });


            result.Append(beginTemplate.TransformText());

            foreach (var item in this.InnerList)
            {
                result.Append(((IInnerItem)item).GetTemplate());
            }

            BootstrapDropDownItemEndTemplate endTemplate = new BootstrapDropDownItemEndTemplate();

            result.Append(endTemplate.TransformText());

            return result.ToString();
        }
    }
}
